﻿using System;
using System.Web.Services;
using Dost.Khcn.Biz;
using Dost.Khcn.Model;

namespace Dost.Khcn.Web.WebOnline
{
    public partial class Default : System.Web.UI.Page
    {
        #region Properties

        private static LinhVucBiz _linhVucBiz;

        private static LinhVucBiz LinhVucManager
        {
            get { return _linhVucBiz ?? (_linhVucBiz = new LinhVucBiz()); }
        }

        private static HocHamBiz _hocHamBiz;

        private static HocHamBiz HocHamManager
        {
            get { return _hocHamBiz ?? (_hocHamBiz = new HocHamBiz()); }
        }

        private static HocViBiz _hocViBiz;

        private static HocViBiz HocViManager
        {
            get { return _hocViBiz ?? (_hocViBiz = new HocViBiz()); }
        }

        private static ChuyenGiaOnlineBiz _chuyenGiaOnlineBiz;

        private static ChuyenGiaOnlineBiz ChuyenGiaOnlineManager
        {
            get { return _chuyenGiaOnlineBiz ?? (_chuyenGiaOnlineBiz = new ChuyenGiaOnlineBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [WebMethod(EnableSession = true)]
        public static object LinhVucs()
        {
            var items = LinhVucManager.GetAllLinhVucs();
            items.Insert(0, new Data.EntityModel.LinhVuc { Id = 0, Ten = string.Empty });

            return items;
        }

        [WebMethod(EnableSession = true)]
        public static object HocHams()
        {
            var items = HocHamManager.GetAllHocHams();
            items.Insert(0, new Data.EntityModel.HocHam { Id = 0, Ten = string.Empty });

            return items;
        }

        [WebMethod(EnableSession = true)]
        public static object HocVis()
        {
            var items = HocViManager.GetAllHocVis();
            items.Insert(0, new Data.EntityModel.HocVi { Id = 0, Ten = string.Empty });

            return items;
        }

        [WebMethod(EnableSession = true)]
        public static object SearchChuyenGia(int jtStartIndex, int jtPageSize, string jtSorting, SearchChuyenGiaOnlineModel searchModel)
        {
            if (jtPageSize > 25) jtPageSize = 50;
            var totalRecords = ChuyenGiaOnlineManager.SearchChuyenGiaOnlineCount(searchModel);

            var results = ChuyenGiaOnlineManager.SearchChuyenGiaOnline(jtStartIndex, jtPageSize, jtSorting, searchModel);

            return new { Result = "OK", Records = results, TotalRecordCount = totalRecords };
        }
    }
}